/**
 * 成本列表相关操作
 *
*/
import { hasRouteAuth } from '@/utils/permission';
import { AMOUNT_TYPE, SETTLEMENT_STATUS, APPROVAL_STATUS, SEALING_STATUS } from '@/utils/const/cost';
export default {
  components: {
    CostApprovalDialog: () => import('@/components/Cost/costApprovalDialog')
  },
  data() {
    return {
      costIds: 0,
      approvalType: -1,
      isBatch: 0
    };
  },
  methods: {
    // 成本结算状态不是已完成和结算中 并且成本审核状态不是已审核 并且拥有可以审批的权限或者管理员 并且封账状态不等于封账中/已封账
    canApproval({ settlementStatus: sStatus, approvalStatus, sealBillType }) {
      return (hasRouteAuth('crm:cost:approval') || this.isAdmin) &&
      sStatus !== SETTLEMENT_STATUS.SETTLEMENT && sStatus !== SETTLEMENT_STATUS.COMPLETED &&
      approvalStatus === APPROVAL_STATUS.PENDING &&
      sealBillType !== SEALING_STATUS.COMPLETED && sealBillType !== SEALING_STATUS.SEALING;
    },
    // 成本结算状态不是已完成和结算中 并且成本审核状态是已审核 并且拥有可以审批的权限或者管理员 并且封账状态不等于封账中/已封账
    canApprovalCancel({ settlementStatus: sStatus, approvalStatus, sealBillType }) {
      return (hasRouteAuth('crm:cost:approvalCancel') || this.isAdmin) &&
      sStatus !== SETTLEMENT_STATUS.SETTLEMENT && sStatus !== SETTLEMENT_STATUS.COMPLETED &&
      approvalStatus && approvalStatus !== APPROVAL_STATUS.PENDING &&
      sealBillType !== SEALING_STATUS.COMPLETED && sealBillType !== SEALING_STATUS.SEALING;
    },
    // 打开审批弹窗
    costApprovalDialog(type, item = {}) {
      const { id } = item;
      const { SINGLE, BATCH } = AMOUNT_TYPE;
      this.costIds = id ? id.toString() : this.ids;
      this.isBatch = id ? SINGLE : BATCH;
      this.approvalType = type;
      this.$refs.costApproval.openDialog();
    },
    // 成本状态色值获取
    getColor(status) {
      // 审批状态： 0: 待审批 1: 通过 2: 拒绝
      let color = '';
      switch (status) {
        case 0:
          color = '#FD8546';
          break;
        case 1:
          color = '#31CC9C';
          break;
        case 2:
          color = '#FF4E5F';
          break;
      }
      return color;
    },
    // 封账状态
    getSealColor(status) {
      // 审批状态： 0: 待封账 1: 已完成 2: 封账中
      let color = '';
      switch (status) {
        case 0:
          color = '#406EFF';
          break;
        case 1:
          color = '#31CC9C';
          break;
        case 2:
          color = '#FD8546';
          break;
      }
      return color;
    },
    getOrderColor(status) {
      // 订单状态： 0: 草稿中 1: 待发布 2: 待核算 3: 待审批 4: 待封账 5: 封账中 6: 已封账 7: 已完成
      let color = '';
      switch (status) {
        case 0:
          color = '#406EFF';
          break;
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
          color = '#FD8546';
          break;
        case 6:
        case 7:
          color = '#31CC9C';
          break;
      }
      return color;
    },
    getCostColor(status) {
      // 成本状态： 0: '待结算',1: '已完成',2: '结算中',3: '待关联', 5: '已忽略'
      let color = '';
      switch (status) {
        case 0:
          color = '#406EFF';
          break;
        case 1:
          color = '#31CC9C';
          break;
        case 2:
        case 3:
        case 4:
          color = '#FD8546';
          break;
        case 5:
        case 6:
        case 7:
          color = '#31CC9C';
          break;
      }
      return color;
    },
    getWriteOffColor(status) {
      // 核销状态： 0: '待核销', 1: '已完成', 2: '部分核销', 3: '异常核销'
      let color = '';
      switch (status) {
        case 0:
          color = '#406EFF';
          break;
        case 1:
          color = '#31CC9C';
          break;
        case 2:
          color = '#FD8546';
          break;
        case 3:
          color = '#FF4E5F';
          break;
      }
      return color;
    }
  }
};
